package com.ssy.wireless.api.service;

import com.ssy.wireless.entity.LocalResource;
import com.ssy.wireless.mapper.EnterpriseMapper;
import com.ssy.wireless.mapper.LocalResourceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Date;

/**
 * Created by cofey on 16/11/21.
 */
@Service
@Transactional(readOnly = true)
public class ApiLocalResourceService {
    @Autowired
    private LocalResourceMapper localResourceMapper;
    @Autowired
    private EnterpriseMapper enterpriseMapper;

    @Transactional
    public void insert(LocalResource localResource) {
        Assert.notNull(localResource, "本地化资源对象不能为空");
        Assert.hasLength(localResource.getEntName(), "政企名称不能为空");
        Assert.notNull(localResource.getType(), "资源类型不能为空");
        Assert.hasLength(localResource.getImgName(), "资源名称不能为空");
        Long entId = enterpriseMapper.selectEntIdByName(localResource.getEntName());
        Assert.notNull(entId, "当前政企[" + localResource.getEntName() + "]信息不存在");
        localResource.setEntId(entId);
        localResource.setCreateTime(new Date());
        localResourceMapper.insert(localResource);
    }
}
